package gui.actions;

import gui.GuiManager;
import gui.GuiManager.FramesEnum;

import javax.swing.JComponent;
import javax.swing.JOptionPane;

import common.Fictionator;
import common.models.StatisticsModel;

public class StatisticsAction extends WorkerAction {

    private static final long serialVersionUID = 1L;

    private StatisticsModel model;
    
	public StatisticsAction(JComponent owner) {
		super(owner);
	}

	@Override
	public boolean isAllowToRunOperation() {
		return true;
	}
	
	@Override
	public void runOperation() throws Exception {
		//TODO Server call
		Thread.sleep(1000);
		model = Fictionator.getInstance().getStatisticsLogic().getCurrentStatistics();
	}
	
	@Override
	public void operationSucceed() {
		GuiManager.switchFrame(FramesEnum.STATISTICS_FRAME,model);
	}
	
	@Override
	public void operationFailed(Exception e) {
		String errorMsg = "Failed to retrieve statistics from data base";
		String errorTitle = "Retrieve statistics failed";
		JOptionPane.showMessageDialog(getOwner(), errorMsg, errorTitle, JOptionPane.ERROR_MESSAGE);
	}
	

}
